
new Class("controls::View", {
    inherits: controls.Widget,
    
    bindview: function(model){
        this.load_css();
        var self = this;
        
        if (this.html && Object.isElement(this.html)) {
            this.prepareElement(this.html);
        }
        else {
            if (this.html) {
                var val = this.html;
                if (typeof this.html === "string") {
                    if (/^\<(.)+\>.*/.test(this.html)) {//todo: check for spaces, tabs, newlines in the beginning of html string
                        var evaledHtml = jsonT(this.getModel().getModel(), {
                            self: this.html
                        }); //Jst.evaluate_jst(val,this); //TrimPath.processDOMTemplate(val,this);
                        this.prepareElement(this._createElement(evaledHtml));
                    }
                }
                else 
                    if (typeof this.html === "object") {
                        var evaledHtml = jsonT(this.getModel().getModel(), this.html);
                        this.prepareElement(this._createElement(evaledHtml));
                    }
            }
            else {
                var htmlpath = this.assetpath(this.getClassName() + ".html");
                requires(htmlpath, function onloaded(req){
					var evaledHtml = jsonT(self.getModel().getModel(), req.responseText);
					self.constructor.prototype.html = req.responseText;
                    self.prepareElement(self._createElement(evaledHtml));
					
//                    var evaledHtml = Jst.evaluate_jst(req.responseText, self); //TrimPath.processDOMTemplate(req.responseText,self);
//                    self.constructor.prototype.element = req.responseText;
//                    var el = evaledHtml.toHtmlElement().cloneNode(true);
//                    self.prepareElement(el); //todo: rename prepareElement
                });
            }
		}
    },
    
    _createElement: function(html_string){
        var element = html_string.toHtmlElement();
        if (element && Object.isElement(element)) {
            return element;
        }
        else {
            throw Error("Could not parse html into a dom element\n" + html_string)
        }
    }
});
